package com.snack.system.controller;

import com.snack.common.core.web.controller.BaseController;
import com.snack.common.core.web.domain.AjaxResult;
import com.snack.common.core.web.page.TableDataInfo;
import com.snack.common.log.annotation.Log;
import com.snack.common.log.enums.BusinessType;
import com.snack.common.security.annotation.RequiresPermissions;
import com.snack.system.domain.TsReviews;
import com.snack.system.service.ITsReviewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评价Controller
 * 
 * @author snack
 * @date 2022-09-18
 */
@RestController
@RequestMapping("/reviews")
public class TsReviewsController extends BaseController
{
    @Autowired
    private ITsReviewsService reviewsService;

    /**
     * 查询评价列表
     */
    @RequiresPermissions("system:reviews:list")
    @GetMapping("/list")
    public TableDataInfo list(TsReviews reviews)
    {
        startPage();
        List<TsReviews> list = reviewsService.selectList(reviews);
        return getDataTable(list);
    }


    /**
     * 获取评价详细信息
     */
    @RequiresPermissions("system:reviews:query")
    @GetMapping(value = "/{reviewsId}")
    public AjaxResult getInfo(@PathVariable("reviewsId") Long reviewsId)
    {
        return AjaxResult.success(reviewsService.selectById(reviewsId));
    }

    /**
     * 新增评价
     */
    @RequiresPermissions("system:reviews:add")
    @Log(title = "评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TsReviews reviews)
    {
        return toAjax(reviewsService.insert(reviews));
    }

    /**
     * 修改评价
     */
    @RequiresPermissions("system:reviews:edit")
    @Log(title = "评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TsReviews reviews)
    {
        return toAjax(reviewsService.update(reviews));
    }

    /**
     * 删除评价
     */
    @RequiresPermissions("system:reviews:remove")
    @Log(title = "评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reviewsIds}")
    public AjaxResult remove(@PathVariable Long[] reviewsIds)
    {
        return toAjax(reviewsService.deleteByIds(reviewsIds));
    }
}
